package com.doit.day03

import scala.collection.mutable

object _09_Map集合 {
  def main(args: Array[String]): Unit = {
    //key value
    val map: mutable.HashMap[String, Int] = new mutable.HashMap[String, Int]()
    map.put("zss",19)
    map.put("lss",19)
    map.put("ww",19)
    map.put("zl",19)
    map.put("qianjin",19)

    //返回的类型啊，不一定就是有值的，可能是一个int类型的值，当然也有可能是 null  Option[Int]
    val maybeInt: Option[Int] = map.get("zss")
    if (maybeInt.isDefined){
      val value: Int = maybeInt.get
      println(value)
    }else{
      //none 上代表没有值，取get自然报错
//      val value: Int = maybeInt.get
      println("不存在这个key")
    }


    //用这个直接能获取到对应的值
    val i: Int = map.getOrElse("zss", 0)


    val map1: Map[String, Int] = Map("zss" -> 18, "lss" -> 19, "ww" -> 20)

    for (elem <- map1) {
      println(elem._1)
      println(elem._2)
    }


    //两个元素的元祖，称之为对偶元祖
    val map3: Map[String, Int] = Map(("zss", 19), ("lss", 18), ("ww", 20), ("qianjin", 17))



  }

}
